//----------------Sonic CD Flying Bird Script-----------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
#alias Object.Value0			:	Object.Timer
#alias Object.Value1			:	Object.Angle

// HUD alias
#alias Object[24].PropertyValue	:	HUD.CurrentTimePeriod

// States
#alias 0	:	FLYINGBIRD_FLYRIGHT
#alias 1	:	FLYINGBIRD_FLYLEFT

// Time Period Aliases
#alias 2	:	TIME_GOOD_FUTURE


sub ObjectMain
	switch Object.State
	case FLYINGBIRD_FLYRIGHT
		if Object.Angle > 0
			Object.Angle -= 2
		else
			// Apex reached, turn around
			
			Object.State	 = FLYINGBIRD_FLYLEFT
			Object.Direction = FACING_LEFT
		end if
		break
		
	case FLYINGBIRD_FLYLEFT
		if Object.Angle < 256
			Object.Angle += 2
		else
			// Crest of the path reached, turn right back around again
			
			Object.State	 = FLYINGBIRD_FLYRIGHT
			Object.Direction = FACING_RIGHT
		end if
		break
		
	end switch
	
	// Animate the Bird
	Object.Timer++
	if Object.Timer > 19
		Object.Timer = 0
		
		Object.Frame++
		Object.Frame &= 1
	end if
	
end sub


sub ObjectDraw
	if MetalSonic_Destroyed == true
		Cos(TempValue0, Object.Angle)
		TempValue0 <<= 14
		TempValue0  += Object.XPos
		
		Sin(TempValue1, Object.Angle)
		TempValue1 <<= 14
		TempValue1  += Object.YPos
		
		DrawSpriteFX(Object.Frame, FX_FLIP, TempValue0, TempValue1)
	else
		if HUD.CurrentTimePeriod == TIME_GOOD_FUTURE
			Cos(TempValue0, Object.Angle)
			TempValue0 <<= 14
			TempValue0  += Object.XPos
			
			Sin(TempValue1, Object.Angle)
			TempValue1 <<= 14
			TempValue1  += Object.YPos
			
			DrawSpriteFX(Object.Frame, FX_FLIP, TempValue0, TempValue1)
		end if
	end if
	
end sub


sub ObjectStartup
	
	LoadSpriteSheet("R2/Objects.gif")
	
	SpriteFrame(-12, -8, 24, 16, 210, 1)	// #0 - Swallow Frame 0
	SpriteFrame(-12, -8, 24, 16, 210, 18)	// #1 - Swallow Frame 1
	
	// Find and setup all Flying Bird Objects in the Level
	ArrayPos0 = 32
	while ArrayPos0 < 1056
		if Object[ArrayPos0].Type == TypeName[Flying Bird]
			
			// Make all Flying Birds draw ontop of other objects & level tiles
			Object[ArrayPos0].DrawOrder = 5
			
		end if
		
		ArrayPos0++
	loop
	
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
end sub


sub RSDKLoad
	LoadSpriteSheet("R2/Objects.gif")
	SpriteFrame(-12, -8, 24, 16, 210, 1)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub
